//
//  IGArticleCell.m
//  jingdongfang
//
//  Created by BOE on 2017/8/28.
//  Copyright © 2017年 LJL. All rights reserved.
//

#import "IGArticleCell.h"

static NSString *const kIGArticleCell = @"kIGArticleCell";
@interface IGArticleCell ()

@property (nonatomic, strong) UIImageView *imgView;
@property (nonatomic, strong) UILabel *titleLable;
@property (nonatomic, strong) UILabel *contentLabel;

@end

@implementation IGArticleCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

+ (IGArticleCell *)cellWithTableView:(UITableView *)tableView {
    IGArticleCell *cell = [tableView dequeueReusableCellWithIdentifier:kIGArticleCell];
    if (!cell) {
        cell = [[IGArticleCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:kIGArticleCell];
    }
    return cell;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self createUI];
    }
    return self;
}

- (void)createUI {
    _titleLable = [UILabel new];
    _titleLable.numberOfLines = 1;
    _titleLable.font = [UIFont font16];
    _titleLable.lineBreakMode = NSLineBreakByTruncatingTail;
    _titleLable.textColor = [UIColor c4Color];
    [self.contentView addSubview:_titleLable];
    
    _imgView = [UIImageView new];
    _imgView.backgroundColor = [UIColor mainRandomColor];
    [self.contentView addSubview:_imgView];

    _contentLabel = [UILabel new];
    _contentLabel.numberOfLines = 3;
    _contentLabel.lineBreakMode = NSLineBreakByTruncatingTail;
    _contentLabel.font = [UIFont font12];
    _contentLabel.textColor = [UIColor c5Color];
    [self.contentView addSubview:_contentLabel];

    UIView *lineView = [[UIView alloc] init];
    lineView.backgroundColor = [UIColor mainBackgroundColor];
    [self.contentView addSubview:lineView];
    
    [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.mas_equalTo(0);
        make.height.mas_equalTo(5);
    }];
    
    [_imgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-kGAP15);
        make.top.mas_equalTo(kGAP15);
        make.width.mas_equalTo(90);
        make.bottom.mas_equalTo(lineView.mas_top).offset(-kGAP15);
    }];
    
    [_titleLable mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.mas_equalTo(kGAP15);
        make.right.mas_equalTo(_imgView.mas_left).offset(-10);
        make.height.mas_equalTo(16);
    }];
    
    [_contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(_titleLable.mas_bottom).offset(10);
        make.left.mas_equalTo(kGAP15);
        make.right.mas_equalTo(_imgView.mas_left).offset(-10);
        make.bottom.mas_equalTo(lineView.mas_top).offset(-kGAP15);
    }];
}

- (void)setSpecial:(IGSpecial *)special {
    _special = special;
    
    [self.imgView sd_setImageWithURL:[NSURL URLWithString:special.image]];
    self.titleLable.text = special.title;
    self.contentLabel.text = special.content;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
